/* memLib.h - memory management library header file */

/* Copyright 2003-2005 Neotune Information Technology Co., Ltd. */

#ifndef __INCmemLibh
#define __INCmemLibh

#ifdef __cplusplus
extern "C" {
#endif

#include "neos_vx_win.h"


/* status codes */

#define S_memLib_NOT_ENOUGH_MEMORY        (M_memLib | 1)
#define S_memLib_INVALID_NBYTES            (M_memLib | 2)
#define S_memLib_BLOCK_ERROR            (M_memLib | 3)
#define S_memLib_NO_PARTITION_DESTROY        (M_memLib | 4)
#define S_memLib_PAGE_SIZE_UNAVAILABLE        (M_memLib | 5)

/* types */

#ifndef _ASMLANGUAGE

typedef struct mem_part *PART_ID;

/* Partition statistics structure */

typedef struct
    {

    unsigned long numBytesFree,       /* Number of Free Bytes in Partition       */
          numBlocksFree,   /* Number of Free Blocks in Partition      */
          maxBlockSizeFree,/* Maximum block size that is free.          */
          numBytesAlloc,   /* Number of Allocated Bytes in Partition  */
          numBlocksAlloc;  /* Number of Allocated Blocks in Partition */

    }  MEM_PART_STATS;
#endif /* ~ _ASMLANGUAGE */

/* partition options */

/* optional check for bad blocks */

#define MEM_BLOCK_CHECK            0x10

/* response to errors when allocating memory */

#define MEM_ALLOC_ERROR_LOG_FLAG    0x20
#define MEM_ALLOC_ERROR_SUSPEND_FLAG    0x40

/* response to errors when freeing memory */

#define MEM_BLOCK_ERROR_LOG_FLAG    0x80
#define MEM_BLOCK_ERROR_SUSPEND_FLAG    0x100

/* old style allocation errors - block too big, insufficient space */

#define MEM_ALLOC_ERROR_MASK        0x03
#define MEM_ALLOC_ERROR_RETURN        0
#define MEM_ALLOC_ERROR_LOG_MSG        0x01
#define MEM_ALLOC_ERROR_LOG_AND_SUSPEND    0x02

/* old style bad block found */

#define MEM_BLOCK_ERROR_MASK        0x0c
#define MEM_BLOCK_ERROR_RETURN        0
#define MEM_BLOCK_ERROR_LOG_MSG        0x04
#define MEM_BLOCK_ERROR_LOG_AND_SUSPEND    0x08


#ifndef _ASMLANGUAGE

/* variable declarations */

/* system partition */

extern PART_ID memSysPartId;

/* shared memory manager function pointers */

extern FUNCPTR  smMemPartOptionsSetRtn;
extern FUNCPTR  smMemPartFindMaxRtn;
extern FUNCPTR  smMemPartReallocRtn;
extern FUNCPTR  smMemPartShowRtn;

/* function declarations */

#if defined(__STDC__) || defined(__cplusplus)

extern STATUS     memInit (char *pPool, unsigned poolSize);
extern STATUS     memPartLibInit (char *pPool, unsigned poolSize);
extern PART_ID     memPartCreate (char *pPool, unsigned poolSize);
extern void     memPartInit (PART_ID partId, char *pPool, unsigned poolSize);
extern STATUS     memPartAddToPool (PART_ID partId, char *pPool,
                  unsigned poolSize);
extern void     memAddToPool (char *pPool, unsigned poolSize);
extern void *    memPartAlloc (PART_ID partId, unsigned nBytes);
extern void *   memPartAlignedAlloc (PART_ID partId, unsigned nBytes,
                     unsigned alignment);
extern void *    memalign (unsigned alignment, unsigned size);
extern void *   valloc (unsigned size);
extern STATUS     memPartFree (PART_ID partId, char *pBlock);
extern STATUS     memPartOptionsSet (PART_ID partId, unsigned options);
extern int     memFindMax (void);
extern int     memPartFindMax (PART_ID partId);
extern void *    memPartRealloc (PART_ID partId, char *pBlock, unsigned nBytes);
extern void     memOptionsSet (unsigned options);
extern STATUS     cfree (char *pBlock);
extern void     memShowInit (void);
extern void     memShow (int type);
extern STATUS     memPartShow (PART_ID partId, int type);
extern STATUS   memPartInfoGet (PART_ID    partId, MEM_PART_STATS * ppartStats);

#else    /* __STDC__ */

extern STATUS     memInit ();
extern STATUS     memPartLibInit ();
extern PART_ID     memPartCreate ();
extern void     memPartInit ();
extern STATUS     memPartAddToPool ();
extern void     memAddToPool ();
extern void *    memPartAlloc ();
extern void *   memPartAlignedAlloc ();
extern void *    memalign ();
extern void *   valloc ();
extern STATUS     memPartFree ();
extern STATUS     memPartOptionsSet ();
extern int     memFindMax ();
extern int     memPartFindMax ();
extern void *    memPartRealloc ();
extern void     memOptionsSet ();
extern STATUS     cfree ();
extern void     memShowInit ();
extern void     memShow ();
extern STATUS     memPartShow ();
extern STATUS   memPartInfoGet ();

#endif    /* __STDC__ */

#endif /* _ASMLANGUAGE */

#ifdef __cplusplus
}
#endif

#endif /* __INCmemLibh */
